package com.wyx.search.web;

import com.hmall.clients.ItemClient;
import com.hmall.common.dto.PageDTO;
import com.wyx.search.pojo.ItemDoc;
import com.wyx.search.pojo.RequestParams;
import com.wyx.search.service.ISearchService;
import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.sort.SortOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
@Slf4j
@RequestMapping("/search")
public class searchController {

    @Autowired
    private ISearchService iSearchService;

    @PostMapping("/list")
    public PageDTO<ItemDoc> search(@RequestBody RequestParams requestParams) throws IOException {

        log.info("{}",requestParams);

        PageDTO<ItemDoc> p = iSearchService.searchByPage(requestParams);
        return p;
    }

    //@PostMapping("/filters")
    public PageDTO<ItemDoc> searchByConn(@RequestBody RequestParams requestParams) throws IOException {

        log.info("{}",requestParams);

        PageDTO<ItemDoc> p = iSearchService.searchByConn(requestParams);
        return p;
    }

}
